package com.audaque.springboot.foshanupload.web.mpguidemo.mpgt.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
import com.audaque.springboot.foshanupload.web.mpguidemo.mpgt.entity.*;
import com.audaque.springboot.foshanupload.web.mpguidemo.mpgt.req.*;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;

import org.springframework.http.HttpStatus;
import com.audaque.springboot.foshanupload.web.mpguidemo.mpgt.service.IUserService;
import com.audaque.springboot.foshanupload.web.mpguidemo.mpgt.entity.User;
import org.springframework.beans.factory.annotation.Autowired;



import io.swagger.v3.oas.annotations.media.Schema;




import lombok.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chinaben
 * @since 2025-05-15
 */
@RestController

@Api(value = " 前端控制器")

@RequestMapping("/user")
public class UserController {


    @Autowired
    private IUserService iUserService;

    @PostMapping(value = "/page")
    @ApiOperation(value = " 分页查询")
    public Page<User> page(@RequestBody UserReq req) {
        QueryWrapper queryWrapper = new QueryWrapper(req);
        Page<User> page = iUserService.page(new Page<>(req.getPage(), req.getRows()),queryWrapper);
        return page;
    }




    @PostMapping(value = "/list")
    @ApiOperation(value = " 列表查询")
    public List<User> list(@RequestBody UserReq req) {
        QueryWrapper queryWrapper = new QueryWrapper(req);
        List<User> list = iUserService.list(queryWrapper);
        return list;
    }





    @GetMapping(value = "/{id}")
     @ApiOperation(value = " 单体查询")
    public User getById(@PathVariable("id") String id) {
        User one=iUserService.getById(id);
        return one;
    }

    @PostMapping(value = "/create")
     @ApiOperation(value = " 创建")
    public void create(@RequestBody User params) {
        iUserService.save(params);
    }

    @PostMapping(value = "/delete/{id}")
     @ApiOperation(value = " 删除")
    public void delete(@PathVariable("id") String id) {
        iUserService.removeById(id);
    }

    @PostMapping(value = "/update")
     @ApiOperation(value = " 更新")
    public void update(@RequestBody User params) {
        iUserService.updateById(params);
    }
}
